
global datapath "~/DataFolder"
global Analyses "~/Results"


*************************************************** Table 5: CS - Info Asymmetry
use "$datapath/RegData.dta", clear

global controls riskiness male avg_minority branch distance numsbl lretain size loan deposit p_ci p_re roa liquid
global controls_nodistance riskiness male avg_minority branch  numsbl lretain size loan deposit p_ci p_re roa liquid

gen user_loc=stcnty
gen fr_loc=fips
merge m:1 user_loc fr_loc using FB_Distance.dta
drop if _merge==2
drop _merge

winsor2 scaled_sci mi_to_county,cut(2.5 97.5) by(year) replace

cd "$Analyses"

* Distance
capture drop m std hvar spec_hvar
egen m = mean(mi_to_county)
egen std = sd(mi_to_county)
gen hvar= (mi_to_county - m) / std
gen spec_hvar=spec_above5pctemp * hvar

reghdfe num spec_above5pctemp hvar spec_hvar $controls_nodistance, absorb(county_year bank_state) cluster(fips)
outreg2 using Table5.xls, replace label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes) 

reghdfe volume spec_above5pctemp hvar spec_hvar $controls_nodistance, absorb(county_year bank_state) cluster(fips)
outreg2 using Table5.xls, append label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes) 


* FB Connection
capture drop m std hvar spec_hvar
egen m=mean(scaled_sci)
egen std=sd(scaled_sci)
capture drop hvar spec_hvar
gen hvar=(scaled_sci-m)/std
gen spec_hvar=spec_above5pctemp * hvar

reghdfe num spec_above5pctemp hvar spec_hvar $controls, absorb(county_year bank_state) cluster(fips)
outreg2 using Table5.xls, append label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes) 

reghdfe volume spec_above5pctemp hvar spec_hvar $controls, absorb(county_year bank_state) cluster(fips)
outreg2 using Table5.xls, append label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes) 








**************************************************** Table 6: CS - Borrower Risk

use "$datapath/RegData.dta", clear

global controls riskiness male avg_minority branch distance numsbl lretain size loan deposit p_ci p_re roa liquid

merge m:1 fips year using HPI_Volatility.dta
drop if _merge==2
drop _merge

winsor2 vol5_hpi1990, by(year) cut(2.5 97.5) replace

bys fips year: egen county_volume=sum(total_volume)
gen p_vol=total_volume/county_volume
gen w_riskiness=riskiness*p_vol
bys fips year: egen county_riskiness=sum(w_riskiness)
drop county_volume p_vol w_riskiness

winsor2 county_riskiness, by(year) cut(2.5 97.5) replace

cd "$Analyses"

* Housing Price Volatility
capture drop m s hvar spec_hvar
egen m=mean(vol5_hpi1990)
egen s=sd(vol5_hpi1990)
gen hvar=(vol5_hpi1990-m)/s
gen spec_hvar=spec_above5pctemp * hvar

*drop hvar because of FE
reghdfe num spec_above5pctemp spec_hvar $controls , absorb(county_year bank_state) cluster(fips)
outreg2 using Table6.xls, replace label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes) 

reghdfe volume spec_above5pctemp spec_hvar $controls , absorb(county_year bank_state) cluster(fips)
outreg2 using Table6.xls, append label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes) 


* Loan to Income Ratio
capture drop m s hvar spec_hvar
egen m=mean(county_riskiness)
egen s=sd(county_riskiness)
gen hvar=(county_riskiness-m)/s
gen spec_hvar=spec_above5pctemp * hvar

*drop hvar because of FE
reghdfe num spec_above5pctemp spec_hvar $controls , absorb(county_year bank_state) cluster(fips)
outreg2 using Table6.xls, append label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes) 

reghdfe volume spec_above5pctemp spec_hvar $controls , absorb(county_year bank_state) cluster(fips)
outreg2 using Table6.xls, append label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes) 












**************************************** Table 7: CS - Size and Real Estate Loan

use "$datapath/RegData.dta", clear

global controls riskiness male avg_minority branch distance numsbl lretain size loan deposit p_ci p_re roa liquid

*size
capture drop hvar spec_hvar
egen m=mean(size)
egen s=sd(size)
gen hvar=(size-m)/s
gen spec_hvar = spec_above5pctemp * hvar

reghdfe num spec_above5pctemp hvar spec_hvar riskiness male avg_minority branch distance numsbl lretain loan deposit p_ci p_re roa liquid , absorb(county_year bank_state) cluster(fips)
outreg2 using Table7.xls, replace label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes)

reghdfe volume spec_above5pctemp hvar spec_hvar riskiness male avg_minority branch distance numsbl lretain loan deposit p_ci p_re roa liquid , absorb(county_year bank_state) cluster(fips)
outreg2 using Table7.xls, append label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes)


*re loan
capture drop m s hvar spec_hvar
egen m=mean(p_re)
egen s=sd(p_re)
gen hvar=(p_re-m)/s
gen spec_hvar = spec_above5pctemp * hvar

reghdfe num spec_above5pctemp hvar spec_hvar riskiness male avg_minority branch distance numsbl lretain size loan deposit p_ci roa liquid , absorb(county_year bank_state) cluster(fips)
outreg2 using Table7.xls, append label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes) 

reghdfe volume spec_above5pctemp hvar spec_hvar riskiness male avg_minority branch distance numsbl lretain size loan deposit p_ci roa liquid , absorb(county_year bank_state) cluster(fips)
outreg2 using Table7.xls, append label dec(3) drop(num) nor2 stats(coef se) addstat(Adjusted R-squared,e(r2_a)) addtext(County*Year FE, Yes, Bank*State FE, Yes) 

